package com.ruoyi.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.function.domain.TransferResult;
import com.ruoyi.function.service.ITransferResultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户支付用户记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/function/result")
public class TransferResultController extends BaseController
{
    @Autowired
    private ITransferResultService transferResultService;

    /**
     * 查询商户支付用户记录列表
     */
//    @PreAuthorize("@ss.hasPermi('function:result:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransferResult transferResult)
    {
        startPage();
        List<TransferResult> list = transferResultService.selectTransferResultList(transferResult);
        return getDataTable(list);
    }

    /**
     * 导出商户支付用户记录列表
     */
    @PreAuthorize("@ss.hasPermi('function:result:export')")
    @Log(title = "商户支付用户记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferResult transferResult)
    {
        List<TransferResult> list = transferResultService.selectTransferResultList(transferResult);
        ExcelUtil<TransferResult> util = new ExcelUtil<TransferResult>(TransferResult.class);
        util.exportExcel(response, list, "商户支付用户记录数据");
    }

    /**
     * 获取商户支付用户记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('function:result:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(transferResultService.selectTransferResultById(id));
    }

    /**
     * 新增商户支付用户记录
     */
    @PreAuthorize("@ss.hasPermi('function:result:add')")
    @Log(title = "商户支付用户记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferResult transferResult)
    {
        return toAjax(transferResultService.insertTransferResult(transferResult));
    }

    /**
     * 修改商户支付用户记录
     */
//    @PreAuthorize("@ss.hasPermi('function:result:edit')")
    @Log(title = "商户支付用户记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferResult transferResult)
    {
        return toAjax(transferResultService.updateTransferResult(transferResult));
    }

    /**
     * 删除商户支付用户记录
     */
    @PreAuthorize("@ss.hasPermi('function:result:remove')")
    @Log(title = "商户支付用户记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(transferResultService.deleteTransferResultByIds(ids));
    }

    // 修改状态

    @Log(title = "商户支付用户记录", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TransferResult transferResult)
    {
        return toAjax(transferResultService.changeStatus(transferResult));
    }

}
